import Vue from "vue";
import VueRouter from "vue-router";
import Login from "@/view/login/login.vue";
import Dashboard from "@/view/dashboard/index.vue";
import errorIndex from "@/view/404.vue";
// 首页
import Home from "./modules/home";
// 组织
import departMent from "./modules/departMent";
// 角色
import Role from "./modules/role";
// 员工
import Staff from "./modules/staff";

import Cookies from "js-cookie";
Vue.use(VueRouter);
const router = new VueRouter({
    routes:[
        {
            path:"/login",
            component:Login,
            name:"login"
        },
        {
            path:"/",
            component:Dashboard,
            name:"home",
            redirect:"/home"
        },
        {
            path:"/404",
            component:errorIndex,
            name:"404"
        },
        departMent,
        Home,
        Role,
        Staff,
    ]
})
router.beforeEach((to,from,next)=>{
    if(to.path=="/login"){
        next();
    }else{
        if(Cookies.get("token")){
            next();
        }else{
            next("/login");
        }
    }
    
})
export default router;